package com.example.springbott.controller;


import com.example.springbott.aspactJ.OperationName;
import com.example.springbott.bean.BaseRespVo;
import com.example.springbott.bean.MarketGoods;
import com.example.springbott.bean.common.BaseParam;
import com.example.springbott.bean.zeng.*;
import com.example.springbott.service.AdminGoodsService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: zeng
 * @Description: 商品管理
 * @date: 11:10 2022/11/20
 */
@RestController
@RequestMapping("admin/goods")
public class AdminGoodsController {
    @Autowired
    AdminGoodsService goodsService;


    @RequiresPermissions("admin:goods:list")
    @RequestMapping("list")
    @OperationName("1")
    public BaseRespVo goodsList(BaseParam baseParam, GoodsList goodsList) {
        //展示商品列表
        AdminGoodsListVo adminGoodsListVo = goodsService.goodsList(baseParam, goodsList);
        return BaseRespVo.ok(adminGoodsListVo);

    }

    @RequiresPermissions("admin:goods:delete")
    @RequestMapping("delete")
    @OperationName("1")
    public BaseRespVoInDelete deleteGoods(@RequestBody MarketGoods marketGoods) {
        goodsService.deleteGoods(marketGoods);
        return BaseRespVoInDelete.ok();
    }

    @RequiresPermissions("admin:goods:read")
    @RequestMapping("detail")
    @OperationName("1")
    public BaseRespVo goodsDetail(Integer id) {
        //通过商品id拿到商品信息
        if (id == null || "".equals(id)) {
            return BaseRespVo.invalidParameter("数据错误");
        }
        AdminGoodsDetailVo goodsDetailVo = goodsService.goodsDetail(id);
        return BaseRespVo.ok(goodsDetailVo);
    }

    @RequestMapping("catAndBrand")
    @OperationName("1")
    public BaseRespVo goodsCatAndBrand() {
        //拿到商品类目信息和品牌
        BaseRespVo baseRespVo = goodsService.getCatAndBrand();
        return baseRespVo;
    }

    @RequiresPermissions("admin:goods:create")
    @RequestMapping("create")
    @OperationName("1")
    public BaseRespVo goodsCreate(@RequestBody AdminGoodsCreateBo goodsCreateBo) {
        goodsService.goodsCreate(goodsCreateBo);
        return BaseRespVo.ok("成功");
    }

    @RequiresPermissions("admin:goods:update")
    @RequestMapping("update")
    @OperationName("1")
    public BaseRespVo goodsUpdate(@RequestBody AdminGoodsCreateBo goodsCreateBo) {
        goodsService.goodsUpdate(goodsCreateBo);
        return BaseRespVo.ok("成功");
    }

}
